package com.htfyun.eink.pw.utils;

import android.graphics.Rect;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class PWUtils {

    public static int toCeil(float val) {
        return (int) (Math.ceil(val));
    }

    /**
     * @param view {@link View}
     * @return view 在屏幕上 rect
     */
    public static Rect getRectOfViewOnScreen(@NonNull View view) {
        int[] locationOnScreen = new int[2];
        view.getLocationOnScreen(locationOnScreen);

        return new Rect(locationOnScreen[0], locationOnScreen[1],
                locationOnScreen[0] + view.getWidth(),
                locationOnScreen[1] + view.getHeight());
    }

    public static boolean canViewReceivePointerEvents(@Nullable View view) {
        if (view == null || !view.isAttachedToWindow()) {
            return false;
        }
        if (!view.isEnabled()) {
            return false;
        }
        return view.getVisibility() == View.VISIBLE || view.getAnimation() != null;
    }


}
